package tech.aistar.clothesspringboot.controller;

import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import tech.aistar.clothesspringboot.pojo.Clothes;
import tech.aistar.clothesspringboot.pojo.result.ResultReturn;
import tech.aistar.clothesspringboot.service.ClothesService;
import tech.aistar.clothesspringboot.pojo.ClothesStock;


import java.util.List;

@RestController
@RequestMapping("/clothes")
@Slf4j
public class ClothesController {
    @Autowired
    private ClothesService clothesService;


    //获取所有的衣服信息
    @GetMapping("/getClothesList")
    public List<Clothes> getClothesList() {
        return clothesService.getClothesList();
    }


    @GetMapping("/getClothesPageNum/{pageNum}")
    public List<Clothes> getClothesPageNum(@PathVariable("pageNum") Integer pageNum) {
        return clothesService.getClothesByPage(pageNum,5).getList();
    }

    //根据名字查询衣服信息
    @GetMapping("/getClothesByName/{name}")
    public ResultReturn<List<Clothes>> getClothesByName(@PathVariable("name") String name){
        List<Clothes> clothesList = clothesService.getClothesByName(name);
        return ResultReturn.success(clothesList);
    }
    //根据id查询衣服信息
    @GetMapping("/getClothesById/{id}")
    public ResultReturn<Clothes> getClothesById(@PathVariable("id") Integer id){
        Clothes clothes = clothesService.getClothesById(id);
        return ResultReturn.success(clothes);
    }
    //根据id查询库存
    @GetMapping("/getStockById/{id}")
    public ResultReturn<List<ClothesStock>> getStockById(@PathVariable("id") Integer id){
        List<ClothesStock> stockList = clothesService.getStockById(id);
        return ResultReturn.success(stockList);
    }



}
